<html>
<head><meta charset="utf-8"><title>How to get sysroot and HOST_TARGET_TRIPLE · t-compiler/help · Zulip Chat Archive</title></head>
<h2>Stream: <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/index.html">t-compiler/help</a></h2>
<h3>Topic: <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/How.20to.20get.20sysroot.20and.20HOST_TARGET_TRIPLE.html">How to get sysroot and HOST_TARGET_TRIPLE</a></h3>

<hr>

<base href="https://rust-lang.zulipchat.com">

<head><link href="https://rust-lang.github.io/zulip_archive/style.css" rel="stylesheet"></head>

<a name="240490887"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/How%20to%20get%20sysroot%20and%20HOST_TARGET_TRIPLE/near/240490887" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Kevin Tran <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/How.20to.20get.20sysroot.20and.20HOST_TARGET_TRIPLE.html#240490887">(May 27 2021 at 16:04)</a>:</h4>
<p>In <a href="https://github.com/rust-lang/rust/issues/71519">https://github.com/rust-lang/rust/issues/71519</a>, Gankra suggests to place rust-lld on the path as "ld", and they suggest getting the path of rust-lld using <code>$(rustc --print sysroot)/lib/rustlib/$HOST_TARGET_TRIPLE/bin/rust-lld</code>. Am I supposed to execute rustc to get the sysroot and what sets the env var HOST_TARGET_TRIPLE? Also, is placing rust-lld on the PATH as ld already done? I see in <code>rustc_codegen_ssa::back::linker::GccLinker</code> has a field <code>is_ld</code> which is set to true in some branches of <code>rustc_codegen_ssa::back::linker::LinkerInfo::to_linker</code>.</p>



<a name="240501288"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/How%20to%20get%20sysroot%20and%20HOST_TARGET_TRIPLE/near/240501288" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> bjorn3 <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/How.20to.20get.20sysroot.20and.20HOST_TARGET_TRIPLE.html#240501288">(May 27 2021 at 17:18)</a>:</h4>
<p>There are several functions inside rustc that get the sysroot path. For example <a href="https://github.com/rust-lang/rust/blob/ea78d1edf364dd3a4b5ff430f76e2bdd3a713a45/compiler/rustc_interface/src/util.rs#L300-L391">https://github.com/rust-lang/rust/blob/ea78d1edf364dd3a4b5ff430f76e2bdd3a713a45/compiler/rustc_interface/src/util.rs#L300-L391</a>. <code>filesearch::get_or_default_sysroot</code> would also be an option, but I think the former is the best option. You will likely need to move it to like <code>rustc_session</code> though to be able to access it from the linker code. And you shouldn't read the <code>HOST_TARGET_TRIPLE</code> env var. That is just meant as a stand in for the actual host target triple which you can get using <code>rustc_session::config::host_triple()</code>.</p>



<a name="240501303"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/How%20to%20get%20sysroot%20and%20HOST_TARGET_TRIPLE/near/240501303" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> bjorn3 <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/How.20to.20get.20sysroot.20and.20HOST_TARGET_TRIPLE.html#240501303">(May 27 2021 at 17:18)</a>:</h4>
<p><span class="user-mention" data-user-id="351526">@Kevin Tran</span></p>



<a name="240505543"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/How%20to%20get%20sysroot%20and%20HOST_TARGET_TRIPLE/near/240505543" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Kevin Tran <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/How.20to.20get.20sysroot.20and.20HOST_TARGET_TRIPLE.html#240505543">(May 27 2021 at 17:48)</a>:</h4>
<p>I see that the first option calls <code>filesearch::get_or_default_sysroot</code> as the first option in the list of candidates, and might extend the list of candidates. Since I must choose only one anyway, wouldn't it be better to just call <code>filesearch::get_or_default_sysroot</code>? Why might the extra candidates be better in getting the path of rust-lld?</p>



<a name="240505578"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/How%20to%20get%20sysroot%20and%20HOST_TARGET_TRIPLE/near/240505578" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Kevin Tran <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/How.20to.20get.20sysroot.20and.20HOST_TARGET_TRIPLE.html#240505578">(May 27 2021 at 17:48)</a>:</h4>
<p><span class="user-mention" data-user-id="133247">@bjorn3</span></p>



<a name="240505987"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/How%20to%20get%20sysroot%20and%20HOST_TARGET_TRIPLE/near/240505987" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> bjorn3 <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/How.20to.20get.20sysroot.20and.20HOST_TARGET_TRIPLE.html#240505987">(May 27 2021 at 17:51)</a>:</h4>
<p>The first function also allows finding rust-lld in the default sysroot when <code>--sysroot</code> is passed by for example <code>xargo</code> and the passed in sysroot doesn't have <code>rust-lld</code>. Basically try all paths in order until you find <code>rust-lld</code>.</p>



<a name="240507237"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/How%20to%20get%20sysroot%20and%20HOST_TARGET_TRIPLE/near/240507237" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Kevin Tran <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/How.20to.20get.20sysroot.20and.20HOST_TARGET_TRIPLE.html#240507237">(May 27 2021 at 18:01)</a>:</h4>
<p>Also, why move the sysroot path code to <code>rustc_session</code> instead of <code>rustc_codegen_ssa</code> where I need to use it? Or why not make <code>sysroot_candidates</code> a pub fn?</p>



<a name="240507627"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/How%20to%20get%20sysroot%20and%20HOST_TARGET_TRIPLE/near/240507627" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Kevin Tran <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/How.20to.20get.20sysroot.20and.20HOST_TARGET_TRIPLE.html#240507627">(May 27 2021 at 18:04)</a>:</h4>
<p><span class="user-mention" data-user-id="133247">@bjorn3</span></p>



<a name="240507844"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/How%20to%20get%20sysroot%20and%20HOST_TARGET_TRIPLE/near/240507844" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> bjorn3 <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/How.20to.20get.20sysroot.20and.20HOST_TARGET_TRIPLE.html#240507844">(May 27 2021 at 18:06)</a>:</h4>
<p>just making it pub won't work as rustc_interface depends on rustc_codegen_ssa and not the other way around. moving it to rustc_session makes more sense than rustc_codegen_ssa as rustc_session has most of the rest of the sysroot handling code.</p>



<a name="240508942"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/How%20to%20get%20sysroot%20and%20HOST_TARGET_TRIPLE/near/240508942" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Kevin Tran <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/How.20to.20get.20sysroot.20and.20HOST_TARGET_TRIPLE.html#240508942">(May 27 2021 at 18:14)</a>:</h4>
<p>When I move the code to rustc_session, libc cannot be found. Any ideas why? <span class="user-mention" data-user-id="133247">@bjorn3</span></p>



<a name="240509228"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/How%20to%20get%20sysroot%20and%20HOST_TARGET_TRIPLE/near/240509228" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Kevin Tran <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/How.20to.20get.20sysroot.20and.20HOST_TARGET_TRIPLE.html#240509228">(May 27 2021 at 18:17)</a>:</h4>
<p>oops, all i need to do is just add libc as a dependency</p>



<hr><p>Last updated: Aug 07 2021 at 22:04 UTC</p>
</html>